from flask import Blueprint, request, jsonify
import os
from module.animal import Animal

UPLOAD_FOLDER = "static/uploads"
OUTPUT_FOLDER = "/yy/static/processimg/animaloutputs"

track_bp = Blueprint("track",__name__)


@track_bp.route("/track",methods=["POST"])
def track_detect():
    if "video" not in request.files:
        return jsonify({"error":"无视频文件"}),400

    file = request.files["video"]

    video_path = os.path.join(UPLOAD_FOLDER, file.filename)

    print(video_path)

    file.save(video_path)
    # 生成唯一文件名
    save_path = os.path.join(OUTPUT_FOLDER,file.filename)

    tracker = Animal()
    result = tracker.track_animal(video_path,save_path)

    return result,200
